<template>
    <div class="card sp">
        <div class="card-body ">
            <label for="ed_post" class="form-label">编辑帖子</label>
            <textarea v-model="content" class="form-control" id="ed_post" rows="3"></textarea>
            <button @click="post_submit" type="button" class="btn btn-success btn-sm">发布</button>
        </div>
    </div>
</template>

<script>
    import {ref} from 'vue';
    import $ from 'jquery';
    import { useStore } from 'vuex';


    export default {
        name:"UserProfileWriter",
        setup(porps,context){
            let content =ref('');

            const store=useStore();
            const post_submit= ()=>{
                $.ajax({
                    url:"https://app165.acapp.acwing.com.cn/myspace/post/",
                    type:"POST",
                    data:{
                        content:content.value,
                    },
                    headers:{
                        'Authorization':"Bearer "+store.state.user.access,
                    },
                    success(resp){
                        if(resp.result==="success"){
                            context.emit('post_submit',content.value);
                            content.value="";
                        }
                    }
                });

            }
            return {
                content,
                post_submit,
            };
        }
    }

</script>

<style scoped>
.sp{
    margin-top: 10px;
}
button{
    margin-top: 10px;
}
</style>